const { createProxyMiddleware } = require("http-proxy-middleware");

module.exports = function (app) {
  // API代理配置
  app.use(
    "/api",
    createProxyMiddleware({
      target: "http://localhost:8080",
      changeOrigin: true,
      secure: false,
      logLevel: "debug",
      onError: (err, req, res) => {
        console.error("代理错误:", err);
      },
      onProxyReq: (proxyReq, req, res) => {
        console.log("代理请求:", req.method, req.url);
      },
      onProxyRes: (proxyRes, req, res) => {
        console.log("代理响应:", proxyRes.statusCode, req.url);
      },
    })
  );

  // WebSocket代理配置
  app.use(
    "/ws",
    createProxyMiddleware({
      target: "ws://localhost:8080",
      ws: true,
      changeOrigin: true,
      logLevel: "debug",
    })
  );
};
